#include <QApplication>
#include <QSettings>
#include "FMConfig.h"

namespace Douban
{
	FMConfig::FMConfig()
	{
		ui.setupUi( this );
		readSetting();
	}

	void FMConfig::readSetting()
	{
		QSettings setting( qApp->applicationDirPath() + "/setting.ini", QSettings::IniFormat );
		setting.beginGroup( "DoubanFM" );

		ui.groupBox->setChecked( setting.value( "EnableFM", true ).toBool() );
		ui.alwaysOnTopCB->setChecked( setting.value( "AlwaysOnTop", false ).toBool() );
		ui.showBorederCB->setChecked( setting.value( "ShowBorder", false ).toBool() );
		ui.showInfoCB->setChecked( setting.value( "ShowInfo", true ).toBool() );
		ui.useTrayIcoCB->setChecked( setting.value( "UseTrayIco", true ).toBool() );

		ui.favEdit->setText( setting.value( "FavShortCut", "" ).toString() );
		ui.delEdit->setText( setting.value( "DeleteShortCut", "" ).toString() );
		ui.dislikeEdit->setText( setting.value( "DisLikeShortCut", "" ).toString() );
		ui.nextEdit->setText( setting.value( "NextShortCut", "" ).toString() );
		ui.stopEdit->setText( setting.value( "StopShortCut", "" ).toString() );
		ui.showEdit->setText( setting.value( "ShowShortCut", "" ).toString() );
	}

	void FMConfig::saveSetting()
	{
		QSettings setting( qApp->applicationDirPath() + "/setting.ini", QSettings::IniFormat );
		setting.beginGroup( "DoubanFM" );

		setting.setValue("EnableFM",ui.groupBox->isChecked());
		setting.setValue("AlwaysOnTop",ui.alwaysOnTopCB->isChecked());
		setting.setValue("ShowBorder",ui.showBorederCB->isChecked());
		setting.setValue("ShowInfo",ui.showInfoCB->isChecked());
		setting.setValue("UseTrayIco",ui.useTrayIcoCB->isChecked());

		setting.setValue("FavShortCut",ui.favEdit->text());
		setting.setValue("DeleteShortCut",ui.delEdit->text());
		setting.setValue("DisLikeShortCut",ui.dislikeEdit->text());
		setting.setValue("NextShortCut",ui.nextEdit->text());
		setting.setValue("StopShortCut",ui.stopEdit->text());
		setting.setValue("ShowShortCut",ui.showEdit->text());
	}
} // namespace Douban
